from test1 import MCPClient
import os
import asyncio

CONFIG_PATH = os.path.join(os.path.dirname(__file__), 'mcpmaps.json')

class MapMCPClient(MCPClient):
    def __init__(self, config_path=CONFIG_PATH):
        super().__init__(config_path=config_path)

if __name__ == "__main__":
    async def main():
        client = MapMCPClient()
        print("[测试] 正在连接地图MCPClient...")
        try:
            await client.connect_all()
            print("[测试] 连接成功！")
        except Exception as e:
            print(f"[测试] 连接失败: {e}")
            return

        print("[测试] 可用工具:")
        tools = await client.list_tools()
        for tool in tools:
            print(tool.name, getattr(tool, "description", ""))

        # 用大模型prompt驱动测试amap_weather
        prompt = "最近刚上映的电影有哪些"
        print(f"[测试] 用大模型prompt: {prompt}")
        try:
            async for chunk in client.process_query(prompt):
                if chunk["type"] == "content":
                    print("[大模型回复]", chunk["content"], end="")
                elif chunk["type"] == "tool_call":
                    print(f"\n[调用工具: {chunk['name']}]")
                elif chunk["type"] == "tool_result":
                    print(f"\n[工具返回: {chunk['name']}]:\n{chunk['content']}")
                elif chunk["type"] == "tool_error":
                    print(f"\n[工具错误: {chunk['name']}: {chunk['error']}]")
                elif chunk["type"] == "error":
                    print(f"\n[错误]: {chunk['content']}")
            print("\n[测试] 完成。")
        except Exception as e:
            print(f"[测试] 大模型驱动工具调用失败: {e}")

    asyncio.run(main()) 